#include <iostream>
using std::cout;
using std::endl;

class Complex
{
public:
    Complex(int real,int image)
    : _real(real)
    , _image(image)
    {}

    void print() const{
        cout << _real << " + "
            << _image << "i" << endl;
    }

    Complex & operator+=(const Complex & rhs){
        _real += rhs._real;
        _image += rhs._image;
        return *this;
    }

    Complex & operator++(){
        cout << "Complex的前置++" << endl;
        ++_real;
        ++_image;
        return *this;
    }
    
    //后置++运算符重载函数的参数列表中加上一个int
    //以示与前置++运算符重载函数区分
    Complex operator++(int){
        cout << "Complex的后置++" << endl;
        Complex temp(*this);
        ++_real;
        ++_image;
        return temp;
    }

    friend
    Complex operator+(const Complex & lhs,const Complex & rhs);
private:
    int _real;
    int _image;
};

Complex operator+(const Complex & lhs,const Complex & rhs){
    return Complex(lhs._real + rhs._real,
                   lhs._image + rhs._image);
}


void test0(){
    int a = 10;
    ++a;//a变成11，表达式返回值就是a
    a++;//a变成12，表达式返回值为11（临时变量，自增之前的副本）


    Complex cx1(1,2);
    ++cx1;
    /* cx1.operator++();//本质 */
    cx1.print();

    cx1++;
    //本质，参数随便传一个int型数据，用不上这个参数，比较特别
    /* cx1.operator++(10); */
    cx1.print();
}

int main(void){
    test0();
    return 0;
}
